package com.atguigu.springcloud.alibaba.controller;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Random;

/**
 * @auther zzyy
 * @create 2020-02-23 14:13
 */
@RestController
public class PaymentController {

    @GetMapping(value = "/payment/{id}")
    public String getPayment(@PathVariable("id") Integer id) {
        System.out.println("当前线程id为：" + Thread.currentThread().getName());
        Random random = new Random();
        int length = random.nextInt(10);
        for (int i = 0; i < length; i++) {
            System.out.println("i =" + i);
        }
        return "id" + id;
    }

    @PostMapping(value = "/testMap")
    public Integer testMap(@RequestBody Map<String, String> mapParam) {
        System.out.println("当前线程id为：" + Thread.currentThread().getName());
        Integer returnInt = 0;
        if (mapParam != null) {
            for (Map.Entry<String, String> stringStringEntry : mapParam.entrySet()) {
                System.out.println("key: " + stringStringEntry.getKey() + ", value: " + stringStringEntry.getValue());
            }
            returnInt = mapParam.size();
        }
        return returnInt;
    }

    @PostMapping(value = "/testList")
    public Integer testList(@RequestBody List<String> ids) {
        System.out.println("当前线程id为：" + Thread.currentThread().getName());
        Integer returnInt = 0;
        if (ids != null) {
            for (int i = 0; i < ids.size(); i++) {
                System.out.println("item[" + i + "]=" + ids.get(i));
            }
            returnInt = ids.size();
        }
        return returnInt;
    }
}
